package com.heima.controller;


import com.heima.domain.HhPatient;
import com.heima.dto.PatientDto;
import com.heima.service.IHhPatientService;
import com.heima.thread.UserThreadLocal;
import com.heima.vo.PatientVo;
import com.heima.vo.Result;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 就诊人 前端控制器
 * </p>
 *
 * @author 黑马程序员
 * @since 2023-01-29
 */
@RestController
@RequestMapping("/patient")
public class PatientController {
    @Autowired
    private IHhPatientService ihhPatientService;

    @GetMapping("/list")
    public Result patientList() {

        List<PatientVo> patientVos = ihhPatientService.patientList();
        return Result.success(patientVos);
    }

    @PostMapping("/remove")
    public Result removePatient(@RequestParam String patientId) {
        ihhPatientService.removePatient(patientId);

        return Result.success("");
    }

    @GetMapping
    public Result getPatient(@RequestParam String patientId) {
        HhPatient hhPatient = ihhPatientService.getPatientByPatientId(patientId);
        return Result.success(hhPatient);
    }

    @PostMapping("/save")
    public Result savePatient( @RequestParam(required = false) Integer patientId,@RequestBody PatientDto dto) {
        if (patientId != null) {
             ihhPatientService.updatePatient(dto, patientId);
            return Result.success(null);
        }
        ihhPatientService.savePatient(dto);
        return Result.success(null);
    }
}

